package com.example.mobile2021606129ly0615;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class UserAdapetr extends RecyclerView.Adapter<UserAdapetr.ViewHolder> {
    private List<User> list;

    public UserAdapetr(List<User> list) {
        this.list = list;
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
    TextView tvItemid,tvItemAge,tvItemScore,tvItemName;
        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            tvItemid=itemView.findViewById(R.id.tvItemId);
            tvItemAge=itemView.findViewById(R.id.tvItemAge);
            tvItemName=itemView.findViewById(R.id.tvItemName);
            tvItemScore=itemView.findViewById(R.id.tvItemScore);
        }
    }

    @NotNull
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_user,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull@NotNull UserAdapetr.ViewHolder holder,int position){
        User user=list.get(position);
        holder.tvItemid.setText(String.valueOf(user.get_id()));
        holder.tvItemName.setText(user.getName());
        holder.tvItemAge.setText(String.valueOf(user.getAge()));
        holder.tvItemScore.setText(String.valueOf(user.getScore()));
    }
    @Override
    public int getItemCount(){
        return list.size();
    }

}
